package Terminal.UI.InterfacceConsulente;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.sql.Time;
import java.text.DateFormat;
import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;


import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;

import org.freixas.jcalendar.JCalendarCombo;


import Terminal.Entity.Dominio.ETimeRecord;
import Terminal.UI.PanelComponent;
import Terminal.UI.TimeLoggingFrame;

import com.toedter.calendar.*;


public class PannelloModificaTimerecordStarted extends PannelloModificaTimerecord{
	private ETimeRecord timerecord;
	
	//private JLabel progettonomelabel;
	//private JTextField progettonometextlabel;
	private JLabel timerecordidlabel;
	private JLabel timerecordidtextlabel;
	private JLabel timerecorddatainiziolabel;
	private JTextField timerecorddatainiziotextlabel;
	private JLabel timerecorddatafinelabel;
	private JTextField timerecorddatafinetextlabel;
	private JTextField timerecordtimeiniziotextlabel;
	private JTextField timerecordtimefinetextlabel;
	private Calendar calendar;
	private JLabel timerecorddescrizionelabel;
	private JTextPane timereocorddescrizionetext;

	//private JCalendarCombo timerecordtimeiniziocombo;
	//private JCalendarCombo timerecordtimefinecombo;
	

	public PannelloModificaTimerecordStarted (PanelComponent parent){
		super(parent);
		
	}
	@Override
	public JPanel createComponents() {
		
		pannellocomponente = new JPanel(null);
		pannellocomponente.setBackground(Color.white);
		////////////////////////////////////PANNELLO DI DESCRIZIONE////////////////////////////////////
		
		
		
		timerecordidlabel = new JLabel("Identificatore:");
		timerecordidlabel.setLocation(40,10);
		timerecordidlabel.setPreferredSize(new Dimension(200,40));
		timerecordidlabel.setSize(timerecordidlabel.getPreferredSize());
		timerecordidlabel.setFont(new Font(timerecordidlabel.getFont().getFontName(), Font.PLAIN,size_font_title ));
		pannellocomponente.add(timerecordidlabel);
       
        
        
       
		timerecordidtextlabel= new JLabel("Assegnato automaticamente");
		
		timerecordidtextlabel.setLocation(200,10);
		timerecordidtextlabel.setPreferredSize(new Dimension(200,40));
		timerecordidtextlabel.setSize(timerecordidtextlabel.getPreferredSize());
		pannellocomponente.add(timerecordidtextlabel);
		
		timerecordidtextlabel.setFont(new Font(timerecordidtextlabel.getFont().getFontName(), Font.ITALIC, size_font_values));
	
		timerecorddescrizionelabel = new JLabel("Commento:");
		timerecorddescrizionelabel.setLocation(40, 50);
		timerecorddescrizionelabel.setPreferredSize(new Dimension(200, 40));
		timerecorddescrizionelabel.setSize(timerecorddescrizionelabel.getPreferredSize());
		timerecorddescrizionelabel.setFont(new Font(timerecorddescrizionelabel.getFont().getFontName(), Font.PLAIN,size_font_title ));
		pannellocomponente.add(timerecorddescrizionelabel);
        
		 timereocorddescrizionetext = new JTextPane();
	     timereocorddescrizionetext.setFont(new Font(timereocorddescrizionetext.getFont().getFontName(), Font.ITALIC,size_font_values ));
	        
	     JScrollPane scrollpanetesto = new JScrollPane(timereocorddescrizionetext);
	       
	     scrollpanetesto.setLocation(200,timerecorddescrizionelabel.getLocation().y+5);
	     scrollpanetesto.setPreferredSize(new Dimension(200,30));
	     scrollpanetesto.setSize(scrollpanetesto.getPreferredSize());
	     pannellocomponente.add(scrollpanetesto);

		
	     timerecorddatainiziolabel = new JLabel("Data di inizio:");
	     timerecorddatainiziolabel.setLocation(40, 90);
	     timerecorddatainiziolabel.setPreferredSize(new Dimension(200,40));
	     timerecorddatainiziolabel.setSize(timerecorddatainiziolabel.getPreferredSize());
	     timerecorddatainiziolabel.setFont(new Font(timerecorddatainiziolabel.getFont().getFontName(), Font.PLAIN,size_font_title ));
	     pannellocomponente.add(timerecorddatainiziolabel);
        
	     timerecorddatainiziotextlabel = new JTextField();
	     timerecorddatainiziotextlabel.setEditable(false);
	     timerecorddatainiziotextlabel.setLocation(200,timerecorddatainiziolabel.getLocation().y+5);
	     timerecorddatainiziotextlabel.setPreferredSize(new Dimension(200,30));
	     timerecorddatainiziotextlabel.setSize(timerecorddatainiziotextlabel.getPreferredSize());
	     pannellocomponente.add(timerecorddatainiziotextlabel);
	     timerecorddatainiziotextlabel.setFont(new Font(timerecorddatainiziotextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));
		
		
		timerecordtimeiniziotextlabel =	new JTextField();
		timerecordtimeiniziotextlabel.setEditable(false);
		timerecordtimeiniziotextlabel.setLocation(430, timerecorddatainiziolabel.getLocation().y+5);
		timerecordtimeiniziotextlabel.setPreferredSize(new Dimension(125,30));
		timerecordtimeiniziotextlabel.setSize(timerecordtimeiniziotextlabel.getPreferredSize());
		timerecordtimeiniziotextlabel.setFont(new Font(timerecordtimeiniziotextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));
		pannellocomponente.add(timerecordtimeiniziotextlabel);
	
		timerecorddatafinelabel = new JLabel("Data di Fine:");
		timerecorddatafinelabel.setLocation(40,130);
		timerecorddatafinelabel.setPreferredSize(new Dimension(200,40));
		timerecorddatafinelabel.setSize(timerecorddatafinelabel.getPreferredSize());
		timerecorddatafinelabel.setFont(new Font(timerecorddatafinelabel.getFont().getFontName(), Font.PLAIN,size_font_title ));
		pannellocomponente.add(timerecorddatafinelabel);
		
        

        timerecorddatafinetextlabel = new JTextField();
        timerecorddatafinetextlabel.setEditable(false);
        timerecorddatafinetextlabel.setLocation(200,timerecorddatafinelabel.getLocation().y+5);
		timerecorddatafinetextlabel.setPreferredSize(new Dimension(200,30));
		timerecorddatafinetextlabel.setSize(timerecorddatafinetextlabel.getPreferredSize());
		pannellocomponente.add(timerecorddatafinetextlabel);
		
		timerecorddatafinetextlabel.setFont(new Font(timerecorddatafinetextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));
		
		 timerecordtimefinetextlabel =	new JTextField();
		 timerecordtimefinetextlabel.setEditable(false);
		 timerecordtimefinetextlabel.setLocation(430, timerecorddatafinelabel.getLocation().y+5);
		 timerecordtimefinetextlabel.setPreferredSize(new Dimension(125,30));
		 timerecordtimefinetextlabel.setSize(timerecordtimefinetextlabel.getPreferredSize());
		 timerecordtimefinetextlabel.setFont(new Font(timerecordtimefinetextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));
		 pannellocomponente.add(timerecordtimefinetextlabel);
			
		 timerecorddatafinetextlabel.setFont(new Font(timerecorddatafinetextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));
		
		 super.setSize(timerecorddatafinetextlabel.getLocation().x+timerecorddatafinetextlabel.getSize().width+25,timerecordtimefinetextlabel.getLocation().y+timerecordtimefinetextlabel.getSize().height+25);
		 
		return pannellocomponente;
	}
	
	public void visualizzaElemento(Object obj) {
		this.timerecord = (ETimeRecord) obj;
		Format dateformat= new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy",Locale.ENGLISH);
		Format dateformat2= new SimpleDateFormat("dd/MM/yyyy");
		Format timeformat = new SimpleDateFormat("HH:mm");
		
		try{timerecordidtextlabel.setText(timerecord.getId()+" ");} catch (Exception e) {timerecordidtextlabel.setText("  ");		}
		try{if(timerecord.getDataInizio()!=null) 	
			{
				Date datetemp= timerecord.getDataInizio();
				timerecorddatainiziotextlabel.setText(dateformat2.format(datetemp));
				//Date timetemp = (Date)((DateFormat) timeformat).parse(timeformat.format(datetemp));
				timerecordtimeiniziotextlabel.setText(timeformat.format(datetemp));
			}
		}
		catch (Exception e) {timerecorddatainiziotextlabel.setText("errore");}
		try{if(timerecord.getDataFine()!=null)
			{
				Date datetemp= timerecord.getDataFine();
				timerecorddatafinetextlabel.setText(dateformat2.format(datetemp));
				//Date timetemp = (Date)((DateFormat) timeformat).parse(timeformat.format(datetemp));
				timerecordtimefinetextlabel.setText(timeformat.format(datetemp));
		}
		}
		catch (Exception e) {timerecorddatafinetextlabel.setText(" ");}
		try{if(timerecord.getTesto()!=null) timereocorddescrizionetext.setText(timerecord.getTesto());else timereocorddescrizionetext.setText(" ");} catch (Exception e) { timereocorddescrizionetext.setText(" ");}
		
	}	
	

	
	
	public ETimeRecord catturaElemento(){
		DateFormat dateformat= new SimpleDateFormat("dd/MM/yyyy HH:mm");
		ETimeRecord s = new ETimeRecord();
		
		Date dataInizio = new Date();
		Date dataFine = new Date();	
		try {
			dataInizio = dateformat.parse(timerecorddatainiziotextlabel.getText()+" "+timerecordtimeiniziotextlabel.getText() );
		} catch (ParseException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		try{s.setDataInizio( dataInizio );  }catch (Exception e) {}
		try{s.setDataFine( dataFine);}catch (Exception e) {	}
		try{ s.setTesto(timereocorddescrizionetext.getText());} catch (Exception e){}
				
		return s;
	}
	
	public void setSize(int width, int height){
		super.setSize(width, height);
		if(parent!=null)parent.updateSize();
	}
	
	public void updateSize(){}
	
	
	


}



